﻿using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Office.OneNote
{
    [DebuggerDisplay("Open Sections")]
    [OneNoteXmlElement("OpenSections")]
    internal sealed class OneNoteOpenSections : OneNoteFolder
    {
        private OneNoteObjectCollection<OneNoteSection> _sections;

        internal OneNoteOpenSections(OneNoteHierarchy hierarchy)
            : base(OneNoteObjectId.Empty)
        {
            Hierarchy = hierarchy;
        }

        [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal OneNoteOpenSections(OneNoteObjectId id)
            : base(id)
        {
        }

        internal OneNoteObjectCollection<OneNoteSection> Sections
        {
            get
            {
                if (_sections == null)
                {
                    EnsureStorageInitialized();
                    _sections = new OneNoteObjectCollection<OneNoteSection>(Storage);
                }

                return _sections;
            }
        }

        internal OneNoteSection Open(string path)
        {
            return Storage.Open<OneNoteSection>(path, OneNoteObjectId.Empty, true);
        }
    }
}
